/*
 
   Copyright 2012 Harri Smatt
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
   
 */

package com.swtplayer;

import com.androidquery.AQuery;
import com.common.MyApp;
import com.readystatesoftware.viewbadger.BadgeView;
import com.swtplayer.R;

import android.R.string;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebSettings;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Simple Activity for curl testing.
 * 
 * @author harism
 */
public class LoginActivity extends Activity {

	  
	AQuery aq = new AQuery(LoginActivity.this);
	MyApp _app=MyApp.getInstance();
	int index=0;
	String url ;
	EditText regiest_email;
	EditText regiest_password;
	Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case 1: {
				
			}
				break;
			case 2: {
				Toast toast= Toast.makeText(LoginActivity.this,(String)msg.obj, Toast.LENGTH_LONG);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();
			}
				break;
			default:
				break;
			}
			super.handleMessage(msg);
		};
	};
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login); 
		_app.addActivity(this);
		InitContent();
	}
  
	public void InitContent()
	{
		Button login=(Button)findViewById(R.id.login);
		TextView gotoregiest_txt=(TextView)findViewById(R.id.gotoregiest_txt);
		 regiest_email=(EditText)(findViewById(R.id.regiest_email));
		 regiest_password=(EditText)(findViewById(R.id.regiest_password));
		 Button top_button=(Button)findViewById(R.id.top_button);
			top_button.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent intent =new Intent();
					intent.setClass(LoginActivity.this, MapActivity.class);
					startActivity(intent);
				}
			});
		login.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				final String passwordtxt=regiest_password.getText().toString();
			    final String emailtxt=regiest_email.getText().toString();
			    if(emailtxt.trim().equals("") || passwordtxt.trim().equals(""))
				{
					return;
				}
				String status= _app.LoginUser(emailtxt,passwordtxt , handler);	
				if(status.equals("1"))
				{
					Intent intent =new Intent();
					intent.setClass(LoginActivity.this, MapActivity.class);
					startActivity(intent);
				}
				 
			}
		});
		
		gotoregiest_txt.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent =new Intent();
				intent.setClass(LoginActivity.this, RegiestActivity.class);
				startActivity(intent);
			}
		});
		
	}

 
	
	 
	
	@Override
	protected void onPause() {	 
		super.onPause();
	}
	
	public boolean onOptionsItemSelected(MenuItem item) {
		boolean status = true;
		status=  _app.OptionsItemSelectedOpt(item);
		return status;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		getMenuInflater().inflate(R.menu.home_menu, menu);
		return true;
	}

	

}